<%--
  @desc: 地图
--%>
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
 <meta name="format-detection" content="telephone=no">
 <meta name="apple-mobile-web-app-capable" content="yes">
 <meta name="apple-mobile-web-app-status-bar-style" content="black">
 <script type="text/javascript"
	src="http://api.map.baidu.com/api?v=2.0&ak=BoDHWfB34TUhSDodZSudcbo0"></script>
<script type="text/javascript" src="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.js"></script> 
<script src="<c:url value='/resource/js/jquery-1.8.3.min.js'/>"></script>
<link rel="stylesheet" href="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.css" />
<link rel="stylesheet" type="text/css" href="<c:url value='/resource/wechat/css/global.css'/>">
<style type="text/css">
	body,html,#showMap {
		width: 100%;
		height: 100%;
		overflow: hidden;
		font-family: "微软雅黑";
		margin: 0;
		font-size:1rem;
		line-height:1.5;
	}
	/*#showMap {
		margin-top: 35px;
	}*/
	
	/*
	提示框样式
	*/	
	.pg-load,.toast {
	bottom: 100px;
	position: absolute;
	height: 60px;
	width: 33%;
	background: rgba(0,0,0,0.5);
	left: 35%;
	right: 35%;
	border-radius:3px;
	color: #ffffff;
	display: none;
 }
 
	 .load-msg,.toast-msg {
	 	width: 100%;
	 	height: 100%;
	 	text-align: center;	
	 	padding-top: 15px;
		padding-bottom: 15px;
	 }
	
	 #go_btn_div{text-align: center;}
	#contnet_info {
		line-height: 14px;
		font-size: 12px;
		height: 62px;
		padding: 5px 0;
		overflow: hidden;
		text-overflow: ellipsis;
		word-wrap: normal;
		display: -webkit-box;
		-webkit-line-clamp: 3;
		-webkit-box-orient: vertical;
	}
	#title_div {
		padding-bottom: 5px;
		height: 30px;
		font-size: 14px;
		line-height: 14px;
		border-bottom: 1px solid #eee;
		word-wrap: normal;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
		width: 190px;
	}
	#go_btn_div button {
		font-size: 1rem;
		margin: 8px 7px 0 7px;
		padding: 1px 4px;
		font-family: "微软雅黑";
		background: #2ba4e6;
		border: none;
		border-radius: 3px;
		width: 200px;
		height: 28px;
		color: #fff;
	}

#befort,#next {width: 40%; height: 25px; float: left; font-size: 13px; text-align: center;line-height: 25px; color: #ffffff;}
#next {float: right;}
#pageNum {width: 20%; height: 30px; float: left;}
</style>
<script type="text/javascript" src="<c:url value='/resource/js/common.js'/>"></script>
<title>地图服务</title>
</head>


<body>
<%--<ul class="tab_menu tab_menu_1 clearfix">

   <li></li>
    <li class="menu_li_current"><a href="<c:url value='/weixin/bm/loadmap'/>?searchname=-1&searchid=-1&maplng=-1&maplat=-1">便民地图</a></li>

    <li></li>
</ul>--%>

<!--wrap-page-->
<div id="showMap"></div>
 <div class="hidecons">
 	<ul class="map_bot_ul_hide">
	    <li onclick="search_2('警务室','4060103',this)" name="search_condition" class="ico02">警务室</li>
	    <li onclick="search_2('派出所','4060102',this)" name="search_condition" class="ico03">派出所</li>
 		<li onclick="search_2('公安局','4060101',this)" name="search_condition" class="ico01">公安局</li>
 	</ul>
 </div>
<div class="footer">
	<div class="map_bot">
    	<p class="map_bot_p">雷达扫描到您屏幕范围内有</p>
        <ul class="map_bot_ul">
        	<li onclick="up()" id="ico00" class="ico01">公安</li>
            <li onclick="search_2('加油站','',this)" name="search_condition" id="ico04" class="ico04">加油站</li>
            <li onclick="search_2('自行车租赁点','',this)" name="search_condition" id="ico05" class="ico05">自行车租赁点</li>
            <li onclick="search_2('银行','',this)" name="search_condition" id="ico06" class="ico06">银行</li>
            <li onclick="search_2('公交车站','',this)" name="search_condition" id="ico07" class="ico07">公交车站</li>
            <li onclick="search_2('公厕','',this)" name="search_condition" id="ico08" class="ico08">公厕</li>
            <%--<li onclick="search_2('停车场','',this)" name="search_condition" id="ico09" class="ico09">停车场</li>--%>
			<li onclick="search_2('酒店','',this)" name="search_condition" id="ico09" class="ico09">酒店</li>
        </ul>
    </div>
</div>

</body>
</html>
<script type="text/javascript">
	var g_lat,g_lng = 0;
	var imgSize = new BMap.Size(19,25);//标注气泡大小
	var map = new BMap.Map("showMap");
	var clickObj;
	var save_keyword, save_keyID;//保存的查询条件
	var mobileHeight = $(document).height();//屏幕高度
	var mobileWidth = $(document).width();//屏幕高度
	var pageSize;//搜索结果页总数
	var pageIndex;//当前显示页码
	var totalPoiNum;//数字地图接口返回结果总数
	
	//信息弹出框样式
	var sContent = "<div id='title_div'></div>"+
	"<div id='contnet_info'></div>" + 
    "<div id='go_btn_div'>"+
    "<button id='go_there'>到这里去</button><br>"+
	"</div>";

	litNav();
	var searchName = "${searchname}";
	var searchID = "${searchid}";
	var mapLng = ${maplng==null?-1:maplng};
	var mapLat = ${maplat==null?-1:maplat};
	//地图平移缩放控件
	var top_left_navigation = new BMap.NavigationControl({
		anchor : BMAP_ANCHOR_TOP_LEFT,
		type : BMAP_NAVIGATION_CONTROL_SMALL,
	});
	
	var point = new BMap.Point(125.110456, 46.594888);//初始坐标
	map.centerAndZoom(point, 20);
	map.addControl(top_left_navigation);
	
	//用户当前位置标注点；
	var userLocaMarker = new BMap.Marker(point, {icon: new BMap.Symbol(BMap_Symbol_SHAPE_POINT,{
		scale: 1,//图标缩放大小
	    fillColor: "#3B71CC",//填充颜色
	    fillOpacity: 1,//填充透明度
	    strokeColor: "white",
	    strokeOpacity: .9
	})});
	var showlocalInfo = false;
	var infoArray = new Array();
	var address = "";
	var userGeoc = new BMap.Geocoder();
	userLocaMarker.addEventListener("click", function localInfo(){
		var infoOverlay = new RouteInfoOverlay(userLocaMarker.getPosition(),address); 
		map.addOverlay(infoOverlay);
		infoArray.push(infoOverlay);
		if(!showlocalInfo){
			showlocalInfo = true;
		}else {
			$.each(infoArray, function(i,n){
				map.removeOverlay(n);
			});
			showlocalInfo = false;
		}
	});
	
	//地图定位服务
	var geolocationControl = new BMap.GeolocationControl({
		anchor : BMAP_ANCHOR_TOP_RIGHT,
	});

	geolocationControl.addEventListener("locationError", function(e) {
		finish("定位失败");
	});
	map.addControl(geolocationControl);
	
	var geolocation = new BMap.Geolocation();
	loading("正在定位...")
	geolocation.getCurrentPosition(function(r){
		if(this.getStatus() == BMAP_STATUS_SUCCESS){
			userLocaMarker.setPosition(r.point);
			userGeoc.getLocation(r.point, function(res){
				address = res.addressComponents.city+res.addressComponents.district+"<br>"+res.addressComponents.street+res.addressComponents.streetNumber;
			});
			map.addOverlay(userLocaMarker);
			if(mapLng!="-1" && mapLat!="-1"){
				map.panTo(new BMap.Point(mapLng,mapLat))
				var objs = document.getElementsByName("search_condition");
				var mobj;
				$.each(objs, function(i,n){
					if(n.innerText == searchName){
						mobj = n;
					}
				});
				search_2(searchName, searchID, mobj);
			}else{
				map.panTo(r.point);
			}
			g_lat = r.point.lat;
			g_lng = r.point.lng;
			finish();
		}else {
			finish("定位失败");
		}
	}, {
		enableHighAccuracy : true
	});
	
	var need_moveSearch = false;
	function search_2(keyword, typeID, obj){
		if($(".hidecons").is(":visible")){
			$(".hidecons").hide();
		}
		pageSize = 0;
		pageIndex = 0;
		if("公厕" == keyword)
			map.setZoom(17);
        if("银行" == keyword)
            map.setZoom(17);
        if("公交车站" == keyword)
            map.setZoom(17);
        if("酒店" == keyword)
            map.setZoom(17);
        if("自行车租赁点" == keyword)
            map.setZoom(17);
        if("加油站" == keyword)
            map.setZoom(17);
        if("公安局" == keyword)
            map.setZoom(13);//将地图的层级设置为13
        if("警务室" == keyword)
            map.setZoom(13);//将地图的层级设置为13
        if("派出所" == keyword)
            map.setZoom(10);//将地图的层级设置为10,数据太少
		search(keyword, typeID, obj);

	}
	map.addEventListener("dragend", map_move_search);//地图移动后搜索
	map.addEventListener("zoomend", map_move_search);//地图缩放后搜索
	
	//var mapZoom;
	//当地图拖动后再次查询
	function map_move_search(){
		if(!need_moveSearch)
			return;
		if(save_keyword != ""){
			//mapZoom = map.getZoom();
			search(save_keyword, save_typeID,clickObj);
		}
	}
	
	/*
	检索方法，
	keyword  检索条件字符串
	typeID   ""表示使用百度自己的检索方式，不为空则表示使用数字地图方法查询，typeID内容为查询条件对应的类型ID。
	typeID  :     类型  
	4060101                  公安局
	4060102                 派出所
	4060401                 交巡警
	503                             政府机关
	30501                       银行
	4100304                 加油站
	2020103                 自信车租赁点   
	*/
	var local;
	var poiArray = new Array();
	function search(keyword, typeID, obj){
		clickObj = obj;
		changeID(clickObj);
		myIcon = new BMap.Icon("<c:url value='/resource/wechat/images/icon_marker.png'/>",imgSize);
		myIcon.setImageSize(imgSize);
		save_keyword = keyword;
		save_typeID = typeID;
		map.clearOverlays();
		var circle = new BMap.Circle(map.getCenter(), Math.pow(2,19-map.getZoom())*100, {
			fillColor : "blue",
			strokeWeight : 1,
			fillOpacity : 0.3,
			strokeOpacity : 0.3
		});
		//map.addOverlay(circle);//显示搜索范围
		
		if("" == typeID && "停车场" != keyword){
			/*--------------------------百度地图查询---------------------------------*/
			local = new BMap.LocalSearch(map, {
				renderOptions : {
					map : map,
					autoViewport : false,
				}
			});
			/*Math.pow(2,19-map.getZoom())*100*/
			local.searchInBounds(keyword, map.getBounds());//查询当前屏幕范围
			//local.searchNearby(keyword, map.getCenter(), circle.getRadius());//以圆形为范围进行搜索，半径自定义
			if($("#pageNum").length > 0 && !$("#os-loading").is(":hidden")){
				$(".load-msg").html("");
				$(".load-msg").html("正在查询...");
			}else{
				loading("正在查询...");
			}
			need_moveSearch = false;
			local.setSearchCompleteCallback(function(result){
				//result.getCurrentNumPois();//返回结果数
				need_moveSearch = true;
				pageSize = result.getNumPages();
				pageIndex = result.getPageIndex();
				if(result.getCurrentNumPois() < 1){
					finish("未查询到结果 ");
				}
				else{
					for(var i=0; i<result.getCurrentNumPois(); i++){
						poiArray.push(result.getPoi(i).point.lng+","+result.getPoi(i).point.lat)
					}
					if(pageSize < 2){
						finish();
					}else{
						toNavPage("0");
					}
					/* var local_2 = new BMap.LocalSearch(map, {
						pageCapacity: 50,
						renderOptions : {
							map : map,
							autoViewport : false,
						}
					});
					local_2.searchInBounds(keyword, map.getBounds());
					local_2.setMarkersSetCallback(function (resp){
						var allOverlay = map.getOverlays();
						//先去除local.searchInBounds()方法调用后百度添加的标注气泡
						for (var i = 0; i < allOverlay.length ; i++){
							if("/tcwx/resource/weixin/images/icon_marker.png" != allOverlay[i].getIcon().imageUrl)
								map.removeOverlay(allOverlay[i]);
						}
						//标注用户当前位置
						userLocaMarker.setPosition(new BMap.Point(g_lng,g_lat));
						userGeoc.getLocation(new BMap.Point(g_lng,g_lat), function(res){
							address = res.addressComponents.city+res.addressComponents.district+"<br>"+res.addressComponents.street+res.addressComponents.streetNumber;
						});
						map.addOverlay(userLocaMarker);
						myIcon.setImageUrl("<c:url value='/resource/wechat/images/marker_little.gif'/>");
						myIcon.setSize(new BMap.Size(13,18));
						myIcon.setImageSize(new BMap.Size(13,18));
							//添加自定义标注气泡
							for(var i = 0; i<resp.length; i++ ){
								//myIcon.setImageUrl("<c:url value='/resource/wechat/images/icon_mark"+i+".png'/>");
								var marker = new BMap.Marker(resp[i].point,{icon : myIcon});
								var content = resp[i].address;
								var title = resp[i].title;
								var mak_poi = resp[i].point;
								if(poiArray.in_array(resp[i].point.lng+","+resp[i].point.lat))
									continue;
								map.addOverlay(marker);
								addClickHandler(content,title,mak_poi,marker);
							}
							//map.setZoom(mapZoom);
						}); */
				}
			});
	
			local.setInfoHtmlSetCallback(function(poi, html) {
			});
			
			local.setMarkersSetCallback(function (resp){
			var allOverlay = map.getOverlays();
			//先去除local.searchInBounds()方法调用后百度添加的标注气泡
			for (var i = 0; i < allOverlay.length ; i++){
					map.removeOverlay(allOverlay[i]);
				}
			//标注用户当前位置
			userLocaMarker.setPosition(new BMap.Point(g_lng,g_lat));
			userGeoc.getLocation(new BMap.Point(g_lng,g_lat), function(res){
				address = res.addressComponents.city+res.addressComponents.district+"<br>"+res.addressComponents.street+res.addressComponents.streetNumber;
			});
			map.addOverlay(userLocaMarker);
				//添加自定义标注气泡
				for(var i = 0; i<resp.length; i++ ){
					//myIcon.setImageUrl("<c:url value='/resource/wechat/images/icon_mark"+i+".png'/>");
					var marker = new BMap.Marker(resp[i].point,{icon : myIcon});
					var content = resp[i].address;
					var title = resp[i].title;
					var mak_poi = resp[i].point;
					map.addOverlay(marker);
					addClickHandler(content,title,mak_poi,marker);
				}
				//map.setZoom(mapZoom);
			});
		}else if("停车场" != keyword){
			/*-----------------------------数字地图方式查询-----------------------------*/
			var point_array;//数字地图查询到的各点的坐标的数组
			var points = "";//数字地图查询到的各点拼接成的字符串，各坐标间用;分隔
			var isFirst = true;
			var mapPoint_array = new Array();//存放地点位置的相关信息，主要有：经纬度坐标，地点名称，地点所在街道名称，二维数组
			
			//标注用户当前位置
			userLocaMarker.setPosition(new BMap.Point(g_lng,g_lat));
			userGeoc.getLocation(new BMap.Point(g_lng,g_lat), function(res){
				address = res.addressComponents.city+res.addressComponents.district+"<br>"+res.addressComponents.street+res.addressComponents.streetNumber;
			});
			map.addOverlay(userLocaMarker);
			//将百度坐标转换成数字地图的坐标
//			$.ajax({
//					url:"http://testapi.sz-map.com/test/poi/convert?geometry="+map.getCenter().lng+","+map.getCenter().lat+"&coding=0&encoded=false",
//					type:"get",
//					dataType:"jsonp",
//					timeout: 8000,
//					beforeSend: function () {
//							if($("#pageNum").length > 0 && !$("#os-loading").is(":hidden")){
//								$(".load-msg").html("正在查询...");
//							}else{
//								loading("正在查询...");
//							}
//				         	need_moveSearch = false;
//				    	},
//					success:function(resp){
//						cent_point = resp.geometry.x + "," + resp.geometry.y;
						//获取数字地图的查询结果
            //以大庆市公安局为中心点查询
			$.ajax({
				url: "<c:url value='/api/map/interest' />",
				data : '{"keywords":"' + keyword + '","numPerPage":' + 10 + ',"pageNum":' + (pageIndex+1) + ',"longitude":"' + 125.1060 + '","latitude":"' + 46.6028 + '","distance":' + circle.getRadius() + '}',
				type: "post",
				dataType: "json",
				timeout: 5000,
				contentType : "application/json;charset=utf-8",
				beforeSend: function () {
					if($("#pageNum").length > 0 && !$("#os-loading").is(":hidden")){
						$(".load-msg").html("正在查询...");
					}else{
						loading("正在查询...");
					}
					need_moveSearch = false;
				},
				success:function (resp){
					if(resp&&resp.succ){
//						debugger;
						totalPoiNum = resp.data.totalRow;
						pageSize = Math.ceil(totalPoiNum/10);
//						point_array = resp.poiInfo.pois;
						var _data = resp.data.list;
						for(var i=0;i<_data.length;i++){
							/*if(isFirst){
								points = _data[i].longitude+","+_data[i].latitude;
							}else {
								points += ";" + _data[i].longitude+","+_data[i].latitude;
							}*/
							mapPoint_array[i] = new Array();
							mapPoint_array[i][2] = _data[i].mc;
							mapPoint_array[i][3] = _data[i].mc;
//							mapPoint_array[i][0] = _data[i].longitude;
//							mapPoint_array[i][1] = _data[i].latitude;
							mapPoint_array[i][0] = _data[i].smx;
							mapPoint_array[i][1] = _data[i].smy;
							var marker = new BMap.Marker(new BMap.Point(_data[i].smx,_data[i].smy),{icon:myIcon});// 创建标注,并设置标注图标
							var content = mapPoint_array[i][2];
							var title = mapPoint_array[i][3];
							var mak_poi = new BMap.Point(mapPoint_array[i][0],mapPoint_array[i][1]);
							map.addOverlay(marker);
							addClickHandler(content,title,mak_poi,marker);
						}
						if(pageSize < 2)
							finish();
						else
							toNavPage("1");
//						for(i = 0; i< point_array.length; i++){
//							if(isFirst){
//								points = point_array[i].geometry.x+","+point_array[i].geometry.y;
//							}else {
//								points += ";" + point_array[i].geometry.x+","+point_array[i].geometry.y;
//							}
//							mapPoint_array[i] = new Array();
//							mapPoint_array[i][2] = point_array[i].address;
//							mapPoint_array[i][3] = point_array[i].name;
//							isFirst = false;
//						}
					}else {
						finish("未查询到结果");
					}
					//将数字地图的结果转换成百度的格式显示
					/*$.ajax({
						url:"http://api.map.baidu.com/geoconv/v1/?coords="+points+"&ak=fW3g9wAHo3EMylkxA8Bv3PHX",
						type:"get",
						dataType:"jsonp",
						timeout: 5000,
						success:function (resp){
							for(i = 0; i< resp.result.length; i++){
								mapPoint_array[i][0] = resp.result[i].x;
								mapPoint_array[i][1] = resp.result[i].y;
								//myIcon.setImageUrl("<c:url value='/resource/wechat/images/icon_mark"+i+".png'/>");
								var marker = new BMap.Marker(new BMap.Point(resp.result[i].x,resp.result[i].y),{icon:myIcon});// 创建标注,并设置标注图标
								var content = mapPoint_array[i][2];
								var title = mapPoint_array[i][3];
								var mak_poi = new BMap.Point(mapPoint_array[i][0],mapPoint_array[i][1]);
								map.addOverlay(marker);
								addClickHandler(content,title,mak_poi,marker);
							}
							if(pageSize < 2)
								finish();
							else
								toNavPage("1");
							//map.setZoom(mapZoom);
						},
						error:function (errormsg){
							finish("查询失败");
						}
					});*/
					need_moveSearch = true;
				},
				error:function (errormsg){
					finish("查询失败");
				}
			});
//					},
//					error:function(info){
//						finish("查询失败");
//					}
//				});
		}
		//event.stopPropagation();
		/*---------------------------停车位查询，调用太仓城管接口-------------------------------*/
		if("停车场" == keyword){
			need_moveSearch = false;
			//标注用户当前位置
			userLocaMarker.setPosition(new BMap.Point(g_lng,g_lat));
			userGeoc.getLocation(new BMap.Point(g_lng,g_lat), function(res){
				address = res.addressComponents.city+res.addressComponents.district+"<br>"+res.addressComponents.street+res.addressComponents.streetNumber;
			});
			map.addOverlay(userLocaMarker);
			var parkIcon = new BMap.Icon("<c:url value='/resource/wechat/images/icon_marker.png'/>",imgSize);
			parkIcon.setImageSize(imgSize);
			$.ajax({
				url: "<c:url value='/weixin/query/bmsrv/parking'/>",
				type: "get",
				dataType: "json",
				timeout: 5000,
				beforeSend: function(request){
					if($("#pageNum").length > 0 && !$("#os-loading").is(":hidden")){
						$(".load-msg").html("正在查询...");
					}else{
						loading("正在查询...");
					}
		         	need_moveSearch = false;
				},
				success: function(resp){
					var recodeGeo = new BMap.Geocoder();
					if(resp&&resp.succ){
						var jsons = jQuery.parseJSON(resp.data);
						var json = jsons.result.parkList;
						$.each(json, function(i,n){
							//parkIcon.setImageUrl("<c:url value='/resource/wechat/images/icon_mark"+i+".png'/>");
							var parkMak_poi = new BMap.Point(parseFloat(n.parkLng), parseFloat(n.parkLat));
							var marker = new BMap.Marker(parkMak_poi, {icon: parkIcon});
							var title = n.parkName;
							var totalNum = n.parkCapacity;
							var currentNum =n.seatIdle;
							map.addOverlay(marker);
							recodeGeo.getLocation(parkMak_poi, function (r){
								var content = r.address+"<br>总车位数:"+totalNum+"<br>剩余:"+currentNum;
								addClickHandler(content,title,parkMak_poi,marker);
							});
						})
						finish();
						$("#os-loading").css("-webkit-animation","");
					}
				},
				error: function (errorMsgm, textStatus, errorThrown){
					finish("查询失败");
				}
			});
		}
	}
	
	/*
	地图气泡点击效果，自定义弹出框样式
	content : 弹出框显示内容信息 
	title : 弹出框标题
	mak_poi : 气泡标志的坐标点
	marker : 气泡点对象
	*/
	function addClickHandler(content,title,mak_poi,marker){
		var opts = {
				width: 220,
				height: 130,
			};
			marker.addEventListener("click", function(e){
			infoWindow = new BMap.InfoWindow(sContent,opts);
			infoWindow.addEventListener("open", function(e){
				$("#title_div").text(title);
				$("#contnet_info").html("地址："+content);
				var ii = $("#contnet_info").height();
				goRouteDetl(mak_poi);
			});
			this.openInfoWindow(infoWindow);
		});
	}
	
	function goRouteDetl(mak_poi){
		var sg_lng = g_lng+"";
		var sg_lat = g_lat+"";
		var startpoi = escape(encodeURIComponent(sg_lng.replace(".","_")+","+sg_lat.replace(".","_")));
		var endpoi = escape(encodeURIComponent((mak_poi.lng+"").replace(".","_")+","+(mak_poi.lat+"").replace(".","_")));
		$("#go_there").click(function(){
			setCookie();
			window.location.href = "<c:url value='/weixin/bm/routeinfo/"+startpoi+"/"+endpoi+"'/>";
		})
	}
	
	/**
	将当前地图的信息存入cookie
	信息有：当前地图中心点坐标， 当前地图查询的关键字
	cookie键为：tcwx_BMapInfo
	*/
	function setCookie(){
		var map_center = map.getCenter();
		var exp = new Date();   
	    exp.setTime(exp.getTime() + (30*24*60*60*1000));
	    window.document.cookie = "tcwx_BMapInfo=" + escape (save_keyword+","+save_typeID+","+map_center.lng+","+map_center.lat) + "; expires=" + exp.toGMTString()+";path=/";
	}
	
	function getSquareBounds(centerPoi, r) {
		var a = Math.sqrt(2) * r;

		mPoi = getMecator(centerPoi);
		var x0 = mPoi.x, y0 = mPoi.y;

		var x1 = x0 + a / 2, y1 = y0 + a / 2;
		var x2 = x0 - a / 2, y2 = y0 - a / 2;

		var ne = getPoi(new BMap.Pixel(x1, y1)), sw = getPoi(new BMap.Pixel(x2,
				y2));
		return new BMap.Bounds(sw, ne);
	}
	
	function getMecator(poi) {
		return map.getMapType().getProjection().lngLatToPoint(poi);
	}

	function getPoi(mecator) {
		return map.getMapType().getProjection().pointToLngLat(mecator);
	}
	
	//查询按钮单选效果
	var objID;
	function changeID(obj){
		if(typeof obj === "undefined")
			return;
		if("" != objID && null != objID){
			$("."+objID).attr("id", objID);
		}
		objID = obj.className;
		obj.id = objID + "_hover";
	}
	
	//隐藏查询先出现位置
	function litNav(){
		$(".hidecons").css("bottom",80);
		$(".hidecons").css("left",(mobileWidth-296)/2);
	}
	
	function up(){
		if($(".hidecons").is(":hidden")){
			$(".hidecons").show();
		}else{
			$(".hidecons").hide();
		}
	}
	
	/**
	 * 百度地图自定义覆盖物，显示路线查询结果等
	 * 
	 * point 覆盖物显示位置坐标
	 * text 显示内容信息
	 */
	function RouteInfoOverlay(point, text){
		this._point = point;
		this._text = text;
	}
	RouteInfoOverlay.prototype = new BMap.Overlay();
	RouteInfoOverlay.prototype.initialize = function(mMap){
		this._map = mMap;
		var mdiv = this._div = document.createElement("div");
		mdiv.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
		mdiv.style.position = "absolute";
		mdiv.style.backgroundColor = "#ffffff";
        mdiv.style.border = "1px solid #999999";
        mdiv.style.color = "#3399FF";
        mdiv.style.height = "48px";
        mdiv.style.top = "20px";
        mdiv.style.padding = "4px";
        mdiv.style.lineHeight = "18px";
        mdiv.style.whiteSpace = "nowrap";
        mdiv.style.MozUserSelect = "none";
        mdiv.style.fontSize = "12px"
		var mspan = this._span = document.createElement("span");
		mdiv.appendChild(mspan);
		//mspan.appendChild(document.createTextNode(this._text));
		mspan.innerHTML = this._text;
		
		var arrow = this._arrow = document.createElement("div")
		arrow.style.background = "url(<c:url value='/resource/wechat/images/arrow.png'/>) no-repeat";
		arrow.style.position = "absolute";
        arrow.style.width = "11px";
        arrow.style.height = "17px";
        arrow.style.top = "46px";
        arrow.style.left = "10px";
        arrow.style.overflow = "hidden";
		mdiv.appendChild(arrow);
		
		map.getPanes().labelPane.appendChild(mdiv);
		return mdiv;
	};
	
	RouteInfoOverlay.prototype.draw = function (){
		var map = this._map;
		var pixel = map.pointToOverlayPixel(this._point);
		//设置覆盖物偏移量
		this._div.style.left = pixel.x - parseInt(this._arrow.style.left) -4 + "px";
		this._div.style.top = pixel.y - 75 + "px";
	};
	
	/*
		显示页数跳转菜单
		0： 百度地图
		1： 数字地图
	*/
	function toNavPage(type){
		if(typeof $("#os-loading") === "undefined"){
			return;
		}
		$(".load-msg").html("");
		var h = $("#os-loading").height();
		$("#os-loading").css("height","0px");
		$(".load-msg").html("<a id='befort' onclick='goBefore("+type+")' href='javascript:void(0)'>上一页</a><span id='pageNum'></span><a id='next' onclick='goNext("+type+")' href='javascript:void(0)'>下一页</a>");
		$("#pageNum").text(pageIndex+1);
		if(pageIndex+1 >= pageSize)
			$("#next").css("color","gray");
		if(pageIndex+1 <= 1)
			$("#befort").css("color","gray");
		$("#os-loading").animate({height: h}, 200);
	}
	
	function goBefore(type){
		if(pageIndex == 0)
			return;
		pageIndex = pageIndex - 1;
		if(type == "0")
			local.gotoPage(pageIndex);
		if(type == "1")
			search(save_keyword, save_typeID,clickObj);
	}
	function goNext(type){
		if(pageIndex == (pageSize - 1))
			return;
		pageIndex = pageIndex + 1;
		if(type == "0")
			local.gotoPage(pageIndex);
		if(type == "1")
			search(save_keyword, save_typeID,clickObj);
	}
	
	/*
		对百度查询返回的结果数组进行重新排序
	*/
	var quickSort = function(arr){
		if(arr.length <= 1)
			return arr;
		var pivotIndex = Math.floor(arr.length/2);
		var pivot = arr.splice(pivotIndex, 1)[0];
		var left=[];
		var right=[];
		for(var i=0; i<arr.length; i++){
			if(arr[i] < pivot)
				left.push(arr[i]);
			if(arr[i] >= pivot)
				right.push(arr[i]);
		}
		return quickSort(left).concat([pivot], quickSort(right));
	}
	
	Array.prototype.in_array = function(e)  
	{  
		for(i=0;i<this.length;i++)  
		{  
			if(this[i] == e)  
				return true;  
		}  
			return false;  
	}    
</script>